using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class FAQs : System.Web.UI.UserControl
{
    processFAQ pFAQ;
    protected void Page_Load(object sender, EventArgs e)
    {
        pFAQ = new processFAQ();
        Load_gvwFAQ();
    }    

    private void Load_gvwFAQ()
    {
        gvwFAQ.DataSource = pFAQ.getFAQ();
        gvwFAQ.DataBind();
    }

    protected void gvwFAQ_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvwFAQ.PageIndex = e.NewPageIndex;
        Load_gvwFAQ();
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        string FAQID = pFAQ.getFAQID();
        if (pFAQ.insertFAQ(FAQID, "", "") > 0)
        {
            gvwFAQ.EditIndex = gvwFAQ.Rows.Count;
            Load_gvwFAQ();
        }
    }
    protected void gvwFAQ_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        gvwFAQ.EditIndex = -1;
        Load_gvwFAQ();
    }
    protected void gvwFAQ_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string FAQID = gvwFAQ.DataKeys[e.RowIndex].Value.ToString();
        if (pFAQ.deleteFAQ(FAQID) > 0)
        {
            Load_gvwFAQ();
        }
    }
    protected void gvwFAQ_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gvwFAQ.EditIndex = e.NewEditIndex;
        Load_gvwFAQ();
    }
    protected void gvwFAQ_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string FAQID = gvwFAQ.DataKeys[e.RowIndex].Value.ToString();
        string FAQName = ((TextBox)gvwFAQ.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
        string FAQDetail = ((TextBox)gvwFAQ.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
        if (pFAQ.updateFAQ(FAQID,FAQName,FAQDetail) > 0)
        {
            gvwFAQ.EditIndex = -1;
            Load_gvwFAQ();
        }
    }
    
}

